package com.antler.smt.portal.controller;

import com.antler.smt.portal.annotation.OperateCut;
import com.antler.smt.request.portal.RecruitmentInfoReq;
import com.antler.smt.request.portal.ReleaseProjcetReq;
import com.antler.smt.response.base.Result;
import com.antler.smt.service.portal.PostRecruitmentService;
import com.antler.smt.service.portal.ReleaseProjectService;
import com.antler.smt.validate.DataValidator;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Repository;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.xml.crypto.Data;

/**
 * 采购商、服务商 发布需求
 *
 * @author zhangyi
 * @date 2018/7/11 14:40
 */
@RestController
@RequestMapping("/postRecruitment")
@Api(description = "采购商、服务商 发布招聘需求")
public class PostRecruitmentController extends BaseController {

    @Resource
    private PostRecruitmentService postRecruitmentService;

    @Resource
    private ReleaseProjectService releaseProjectService;

    /**
     * 发布招聘需求

     *  * @param request
     * @return
     */
    @PostMapping("/insertRecruitmentInfo")
    @ApiOperation(value = "采购商，服务商发布招聘需求" +
            "(字段说明：academicRequirement:字符串0 1 2 3 4 分别代表高中 中专 大专 本科 硕士)", httpMethod = "POST")
    @OperateCut(operationContent = "发布招聘信息")
    public Result insertRecruitmentInfo(@RequestBody RecruitmentInfoReq request) {

        DataValidator.isNull(request, "请求实体不为空！");
        DataValidator.isBlank(String.valueOf(request.getJobClassify()), "工作选择不能为空！");
        DataValidator.isBlank(String.valueOf(request.getJobTitle()), "职位名称标题不能为空！");
        DataValidator.isBlank(String.valueOf(request.getRecruitmentCount()), "招聘人数不能为空！");
        DataValidator.isBlank(request.getAcademicRequirement(), "学历要求不能为空！");
        DataValidator.isBlank(String.valueOf(request.getExperienceRequirement()), "经验要求不能为空！");
        DataValidator.isBlank(String.valueOf(request.getAgeRequirement()), "年纪要求不能为空!");
        DataValidator.isBlank(String.valueOf(request.getAgePeopleStart()), "最小年纪不能为空!");
        DataValidator.isBlank(String.valueOf(request.getAgePeopleEnd()), "最大年纪不能为空!");
        DataValidator.isBlank(String.valueOf(request.getSexRequirement()), "性别要求不能为空！");
        DataValidator.isBlank(request.getProvincial(), "省不能为空!");
        DataValidator.isBlank(request.getCity(), "市不能为空!");
        DataValidator.isBlank(request.getCounties(), "区不能为空!");
        DataValidator.isBlank(request.getWorkPlace(), "工作地址不能为空!");
        DataValidator.isBlank(request.getJobDescription(), "工作描述不能为空!");
        DataValidator.isBlank(String.valueOf(request.getSalary()), "薪资不能为空！");
        DataValidator.isBlank(String.valueOf(request.getWorkTime()), "工作时间不能为空！");
        DataValidator.isBlank(String.valueOf(request.getDutyTime()), "要求到岗时间不能为空！");
        DataValidator.isBlank(String.valueOf(request.getWorkStartTime()), "工作开始时间不能为空！");
        DataValidator.isBlank(String.valueOf(request.getWorkEndTime()), "工作结束时间不能为空！");
        //是否同意
        DataValidator.isBlank(String.valueOf(request.getEffective()),"是否同意！");
        return postRecruitmentService.insertRecruitmentInfo(request, currentMember.getId());
    }

    /**
     * 分类查看招聘需求以,隔开
     *
     * @return
     */
    @GetMapping("/selectRecruitmentInfo")
    @ApiOperation(value = "分类查看需求以,隔开(0 未提交待审核、1提交未审核 2 审核通过 3 审核不通过)", httpMethod = "GET")
    @OperateCut(operationContent = "查看招聘需求")
    public Result selectRecruitmentInfo(@RequestParam(value = "status") String status) {
        return postRecruitmentService.selectRecruitmentInfo(currentMember.getId(), status);
    }

    @PostMapping("/click/{id}")
    @ApiOperation(value = "调用此接口，点击一次，此招聘信息就增加一次(传入此招聘需求的id)", httpMethod = "POST")
    @OperateCut(operationContent = "点击招聘信息")
    public Result click(@PathVariable(value = "id") Long id) {
        return postRecruitmentService.updateClickCount(id);
    }


    /**
     * 发布项目
     *
     * @return
     */
    @PostMapping("/releaseProject")
    @ApiOperation(value = "发布项目", httpMethod = "POST")
    @OperateCut(operationContent = "发布项目")
    public Result releaseProject(@RequestBody ReleaseProjcetReq releaseProjectReq) {
        releaseProjectReq.setMemberId(currentMember.getId());
        return releaseProjectService.releaseProject(releaseProjectReq);
    }

    /**
     * 获取发布项目
     *
     * @return
     */
    @GetMapping("/getProject")
    @ApiOperation(value = "获取发布项目", httpMethod = "GET")
    @OperateCut(operationContent = "获取发布项目")
    public Result getProject() {

        return releaseProjectService.getProject(currentMember.getId());
    }
    /**
     * 修改发布项目
     *
     * @return
     */
    @PostMapping("/editProject")
    @ApiOperation(value = "修改发布项目", httpMethod = "POST")
    @OperateCut(operationContent = "修改发布项目")
    public Result editProject(@RequestBody ReleaseProjcetReq releaseProjectReq) {
        releaseProjectReq.setMemberId(currentMember.getId());
        return releaseProjectService.editProject(releaseProjectReq);
    }
}
